home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7858 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: mudskipper.cac.psu.edu!user
  2. From: fcusack@tdx.org (frank.)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: const wasting space and slower?
  5. Date: Mon, 19 Feb 1996 07:35:29 -0400
  6. Organization: Psychic Enemies Network
  7. Message-ID: <fcusack-1902960735290001@mudskipper.cac.psu.edu>
  8. References: <312814DB.399F@iastate.edu>
  9. NNTP-Posting-Host: mudskipper.cac.psu.edu
  10.  
  11. In article <312814DB.399F@iastate.edu>, Steve Lee <sjlee@iastate.edu> wrote:
  12.  
  13. [...]
  14. > When you declare something like this:
  15. > const int MAX_FILES = 20;
  16. > doesn't the compiler reserve global, read-only memory for this
  17. variable?  Or does it just replace 
  18.  
  19. It may reserve space. compile with debugging symbols on, you will see
  20. references to your variable name.
  21.  
  22. > instances in the source code where MAX_FILES is found and replaces it
  23. with 20, similar to a 
  24. > preprocessor, but with typechecking? 
  25.  
  26. Again, that probably depends on compiler switches. I'm sure that with
  27. optimization, you'll lose the variable, since it's a constant. You'll
  28. still retain typechecking. Why don't you check with your compiler?
  29.  
  30. > Also, if the compiler does place it in memory, do 
  31. > instructions then reference the memory, instead of immediate addressing mode?
  32. > If this is so, I think it wastes space (storage of constants) and is
  33. slower (direct addressing 
  34. > mode vs. immediate addressing mode).
  35.  
  36. yes, it probably does, but it vastly helps the write-test-debug process.
  37. When you are thoroughly debugged, you can optimize it away.
  38. ~Frank
  39.  -- I am Pentium of Borg.  Division is futile.  You will be approximated. --
  40.  --   If you build it, they will come --> http://www.tdx.org/~fcusack/    --
  41.  -- PGP key fingerprint: 01 C0 C0 B9 CC 78 67 0F  3F 64 80 65 8B 0F F9 EA --
  42.